﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@model ManagerWeb.Models.TableColumnsViewModel
@{
    Layout = null;
}

<html>
<head>
    <title></title>
    <style type="text/css">
    body {
        word-break: break-word;
        line-height: 1.8;
    }

    .my_code {
        display: block;
        background-color: #f5f5f5;
        font-family: Courier New !important;
        font-size: 12px !important;
        border: 1px solid #ccc;
        padding: 5px;
        overflow: auto;
        margin: 5px 0;
        color: #000;
    }

    pre {
        margin-top: 0;
        margin-bottom: 0;
        font-family: Courier New !important;
        font-size: 12px !important;
        word-wrap: break-word;
        white-space: pre-wrap;
        /* vertical-align: middle;
                text-align: center; */
    }

    code_copy {
        font-family: Courier New !important;
        font-size: 12px !important;
        line-height: 1.5 !important;
        padding-right: 5px;
    }

  </style>
</head>
<body>
    <div id="divCode">
        @if (null != Model && null != Model.Columns && Model.Columns.Count > 0)
        {
        <div class="my_code">
            <input type="button" class="btn btn-primary" value="显示代码" onclick="ShowCode();" style="display: none;" />
            <input type="button" class="btn btn-primary" value="选中代码" onclick="CopyCode(this);" style="display: none;" />
            <span class="code_copy">
                <a href="javascript:void(0);" onclick="CopyCode(this)" title="复制代码">
                    <img src="@Url.Content("~/image/copycode.gif")" alt="复制代码">
                </a>
                <span style="padding-left: 5px;">Ctrl+A</span>
            </span>
            <textarea id="ttCode" class="form-control" rows="@(Model.Columns.Count * 6)" style="display: none;" readonly></textarea>
            <pre id="code">
            using System;
            using System.Collections.Generic;
            using System.Text;

            namespace @Model.DbConnectStringInfo.DatabaseName
            {
                public class @Common.StringHelper.FirstCharUpper(Model.DbConnectStringInfo.TableName)
                {
                    @{ String strPropertyCodeTemplate = ManagerWeb.BllProcessor.TemplateProcessor.GetPropertyTemplateFileContent(); }
                    @foreach (var tmp in Model.Columns)
                    {  
                        @(strPropertyCodeTemplate.Replace("$description$", tmp.Description)
                            .Replace("$datatype$", Common.DatabaseTypeHelper.DbTypeConvertToString(tmp.DataType))
                            .Replace("$propertyname$", Common.StringHelper.FirstCharUpper(tmp.Name)))
                    }
                }
            }
            
        </pre>
        </div>
        }
    </div>
    <script type="text/javascript">
        function CopyCode(dom) {
            $("#code").hide();
            $("#ttCode").show();
            var ttCodeVal = $("#ttCode").val();
            if (!ttCodeVal) {
                var code = $("#code").html();
                ttCodeVal = code.replace(/<span>/g, "").replace(/<\/span>/g, "").replace(/&lt;/g, "<").replace(/&gt;/g, ">");
                $("#ttCode").val(ttCodeVal);
            }

            //var url = $(dom).prev();
            //url.select();
            //document.execCommand("Copy");
            var code = document.getElementById("ttCode");
            code.focus();
            code.select();
            return true;
        }
        //显示代码
        function ShowCode() {
            $("#code").show();
            $("#ttCode").hide();
        }
    </script>
</body>

</html>